// pages/services/services.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    identity:'',
    healthList:
				[
					{
						id: 1,
						image_src:"/static/健康.png",
            name:"健康监测",
            url:'/subpkg/health/health'
					},
					{
						id: 2,
						image_src:"/static/药品.png",
            name:"用药情况",
            url:'/subpkg/medicine/medicine'
					},
					{
						id: 3,
						image_src:"/static/饮食.png",
            name:"饮食记录",
            url:'/subpkg/food/food'
					}
				],
				lifeList:
				[
					
					{
						id: 1,
						image_src:"/static/通话.png",
            name:"通话提醒",
            url:'/subpkg/reminder/reminder'
					},
					{
						id: 2,
						image_src:"/static/账单.png",
            name:"账单查询",
            url:'/subpkg/money/money'
					},
					{
						id: 3,
						image_src:"/static/建议.png",
            name:"建议箱",
            url:'/subpkg/recommend/recommend'
					}
				],
				gameList:
				[
					
						{
							id: 1,
							image_src:"/static/游戏.png",
              name:"游戏",
              url:'/subpkg/game/game'
						},
				]
				

  },
  navigator1(e){
    if(wx.getStorageSync('identity') === '游客'){
      Dialog.confirm({
        title: '提醒',
        message: '您当前是游客身份，请绑定后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.redirectTo({
            url: '/subpkg_worker/login/login',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    else if(wx.getStorageSync('elderId')===''){
      Dialog.confirm({
        title: '提醒',
        message: '您还未绑定老人,请先绑定老人后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.navigateTo({
            url: '/subpkg/my/bindelder/bindelder',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: this.data.healthList[index].url,
    })
  },


  navigator2(e){
    if(wx.getStorageSync('identity') === '游客'){
      Dialog.confirm({
        title: '提醒',
        message: '您当前是游客身份，请绑定后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.redirectTo({
            url: '/subpkg_worker/login/login',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    else if(wx.getStorageSync('elderId')===''){
      Dialog.confirm({
        title: '提醒',
        message: '您还未绑定老人,请先绑定老人后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.navigateTo({
            url: '/subpkg/my/bindelder/bindelder',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: this.data.lifeList[index].url,
    })
  },


  navigator3(e){
    if(wx.getStorageSync('identity') === '游客'){
      Dialog.confirm({
        title: '提醒',
        message: '您当前是游客身份，请绑定后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.redirectTo({
            url: '/subpkg_worker/login/login',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    else if(wx.getStorageSync('elderId')===''){
      Dialog.confirm({
        title: '提醒',
        message: '您还未绑定老人,请先绑定老人后享受更多服务!',
      })
        .then(() => {
          // on confirm
          wx.navigateTo({
            url: '/subpkg/my/bindelder/bindelder',
          })
        })
        .catch(() => {
          // on cancel
        });
        return
    }
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: this.data.gameList[index].url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      identity:wx.getStorageSync('identity')
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.setData({
    //   identity:wx.getStorageSync('identity')
    // })
    // this.setTabBar()
  },
  // setTabBar:function(){
  //   if(typeof this.getTabBar==='function'&&
  //   this.getTabBar()){
  //     this.getTabBar().setData({
  //       selected:1
  //     })
  //   }
  // },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})